package system;
import java.sql.*;
public class userInf{
	String user_id,password;
	String[] userInf={"1","2","3","4","5"};
	boolean whetherMatch=false;
	
	public void setUserId(String s){
		user_id=s.trim();
	}
	public String getUserId(){
		return user_id;
	}
	
	public void setPassword(String s){
		password=s.trim();
	}
	public String getPassword(){
		return password;
	}
	
	public boolean getWhetherMatch(){
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){userInf[0]="300";}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("SELECT * from user_inf where user_id="+"'"+user_id+"'");
		if(rs.next()){
			for(int i=0;i<5;i++){
				userInf[i]=rs.getString(i+1);
				}			
		}
		con.close();
	    } catch(SQLException e1){userInf[2]="100";}
	    if(password.equals(userInf[1].trim())){
	    	whetherMatch=true;
		}else whetherMatch=false;		
		return whetherMatch;
	}
	
	public String[] getUserInf(){
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){userInf[0]="300";}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("SELECT * from user_inf where user_id="+"'"+user_id+"'");
		if(rs.next()){
			for(int i=0;i<5;i++){
				userInf[i]=rs.getString(i+1);
				}			
		}
		con.close();
	    } catch(SQLException e1){userInf[2]="100";}
	    return userInf;
	}
}